define(['jquery'], () => {
    const baseUrl = 'http://www.xmyxapp.com/api'
    const rap2Url = 'http://rap2api.taobao.org/app/mock/231357'
    const mapUrl1 = 'http://apis.map.qq.com/ws/district/v1/list?key=P5OBZ-SBQRF-HMWJE-NAOTH-F5QFK-EWBWC&output=jsonp&callback=?'
    const mapUrl2 = 'http://apis.map.qq.com/ws/district/v1/getchildren?key=P5OBZ-SBQRF-HMWJE-NAOTH-F5QFK-EWBWC&output=jsonp&callback=?'
    const searchUrl = 'https://jf.10086.cn/portal/ware/web/SearchWareAction?action=getSuggest&wt=json&limit=10'
    
    return {
        // 获取列表名称
        getTabs() {
            return new Promise(resolve => {
                $.get(`${rap2Url}/tabs`, resolve)
            })
        },
        // 获取列表页
        getCategory(id) {
            return new Promise(resolve => {
                $.get(`${rap2Url}/tab/${id}`, resolve)
            })
        },
        // 获取详情数据
        getDetail(id) {
            return new Promise(resolve => {
                $.get(`${rap2Url}/detail`, { id }, resolve)
            })
        },

        //获取省
        getProvince() {
            return new Promise(resolve => {
                $.getJSON(`${mapUrl1}`, resolve)
            })
        },

        // 获取市
        getCity(id) {
            return new Promise(resolve => {
                $.getJSON(`${mapUrl2}&id=${id}`, resolve)
            })
        },

        // 获取区
        getArea(id) {
            return new Promise(resolve => {
                $.getJSON(`${mapUrl2}&id=${id}`, resolve)
            })
        },

        // 获取搜索数据
        getSearch(s) {
            return new Promise(resolve => {
                $.getJSON(`${searchUrl}&s=${s}`,resolve)
            })
        }
    }
});